﻿@{
    ViewBag.Title = "在线归档";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}
@section styles{
    <link href="@Url.Content("~/Content/css/common/bootstrap-table/bootstrap-table.min.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/common/animate/animate.min.css")" rel="stylesheet" />

    <style type="text/css">
        .popover {
            height: 300px;
            width: 600px;
            overflow: hidden auto;
        }

        ul li {
            font-size: 11px;
            border-bottom: 1px solid #ccc;
            margin-bottom: 5px;
            margin-right: 10px;
        }
    </style>
}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="ibox-title">
                <h4>在线归档</h4>
            </div>
            <div class="ibox-content">
                <div id="toolbar">
                    <a class="btn btn-sm btn-success radius" href="#" style="margin-top: 10px;"><i class="iconfont icon-tianjia"></i>&nbsp; 一键归档</a>
                    <div class="text-danger" style="font-size: 14px; margin-top: 15px;margin-left: 10px;float:right; "><i class="iconfont icon-tuichiweixuan"></i>&nbsp;提示：双击行可查看该信息的详细！</div>
                </div>
                <table id="DocumentDataTable"></table>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/locale/bootstrap-table-zh-CN.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-export.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/tableExport.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-cookie.js")"></script>
    <script src="@Url.Content("~/Content/js/common/from.js")"></script>
    <script src="@Url.Content("~/Content/js/common/Date.js")"></script>
    <script>
    //var tabHeight = 0;
    $(function () {
        $('#DocumentDataTable').bootstrapTable({
            //  height: tabHeight + 50,
            url: '/Document/Archive/GetDataTableJsonResult',         //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
            //data: $("#dJson").text() != "" ? JSON.parse($("#dJson").text()) : "",
            dataType: "json",
            columns: [
                {
                    title: "标题", field: 'SUBJECT', align: 'center', formatter: function (value, row, index) {
                        //return '<a href="/Document/Send/Details/' + row.DOC_ID + '">' + row.SUBJECT + '</a>';
                        return '<a href="#" onclick="parent.createTab(\'1303\',\'收文明细\',\'/Document/Send/Details/' + row.DOC_ID + '\')">' + row.SUBJECT + '</a>';
                    }
                },
                {
                    title: "文号", field: 'DOC_NUM', align: 'center'
                },
                {
                    title: "发文人", field: 'DRAFT_AUTHOR', align: 'center'
                },
                {
                    title: "发文时间", field: 'CREATE_TIME', align: 'center', formatter: function (value, row, index) {
                        return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                    }
                },
                {
                    title: "状态", field: 'IS_ARCHIVE', align: 'center', formatter: function (value, row, index) {
                        if (value) {
                            return "<span id='archive_status_" + row.DOC_ID + "' style='color:green;'>已归档</span>";
                        }
                        return "<span id='archive_status_" + row.DOC_ID + "' style='color:red;'>未归档</span>";
                    }
                },
                {
                    field: '#',
                    title: "操作",
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        if (!row.IS_ARCHIVE) {
                            return '<a class="btn btn-info btn-xs btn-outline" onclick="fileArchive(this,\'' + row.DOC_ID + '\');"> 归档</a>';
                        }
                        return "-";
                    }
                }
            ],
        toolbar: '#toolbar',//工具按钮用哪个容器
        buttonsClass: "sm btn-white",//按钮class
        pageSize: 10,//分页条数
        clickToSelect: false,//设置true 将在点击行时，自动选择单选或复选框
        singleSelect: false,//为true则禁止多选
        cache: false,//是否缓存
        cookie: true,//是否启用cookie
        cookieIdTable: "Document",//cookie键值
        pagination: true,//是否分页
        showColumns: true,//是否显示所有的列
        showRefresh: true,//是否显示刷新按钮
        search: false,//是否启用搜索
        showPaginationSwitch: true,//是否显示分页切换按钮
        showExport: true,//是否启用导出
        striped: false,//是否显示行间隔色
        detailView: false,//是否显示切换视图列
        //detailFormatter: detailFormatter,//卡片视图内容格式化
        onDblClickRow: function (row, obj) { //双击行事件
            // window.top.showFullPage("图像阅读器（" + (row.FileNo) + "）", "/See.aspx?FID=" + row.ID);
            parent.createTab('1303','收文明细','@Url.Action("Details", "Send", new { area = "Document" })/' + row.DOC_ID + '');
        },
        onClickRow: function (row, obj) { //单击行事件
            $(obj).parent().find("tr").removeClass("selected");
            $(obj).addClass("selected");

            ////根据选中的行获取子表数据
            //GetSonData(row.ID);
        },
        onSearch: function (text) {
            if (text != "") {
                $("#tabData tbody tr td:not(.bs-checkbox)").each(function (i) {
                    var str = "<span class=\"bg-yellow\">" + text + "</span>";
                    var NewText = $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).text().replaceAll(text, str);
                    $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).html(NewText);
                })
            }
            },
            onLoadSuccess: function (data) {
                setTimeout(function () {
                    $('[data-toggle="popover"]').popover();
                }, 1500);
            }
            });

            })

        function fileArchive(ele,id) {
            layer.confirm('是否确定归档？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post("/document/archive/fileArchive", { id: id }, function (response) {
                    if (response.code == 100) {
                        //$(ele).parent().parent().remove();
                        $(ele).parent().html("-");
                        $("#archive_status_" + id).css("color", "green");
                        $("#archive_status_" + id).html("已归档");
                        layer.msg('归档成功！', {
                            icon: 1,
                            time: 2000
                        });
                    }
                });
            });
            return false;

            $.ajax({
                type: "post", //类型
                url: "http://10.42.0.68:8088/api/FileArchive.ashx", //API地址
                dataType: "json", //数据类型
                async: true, //是否异步
                data: {
                    type: "InsertWenShu", //执行方法
                    ND: model.DOC_YEAR, //年度
                    JG: model.DRAFT_UNIT, //机构
                    ZRZ: model.DRAFT_AUTHOR, //责任者
                    WH: model.DOC_NUM, //文号
                    AJTM: model.SUBJECT, //案卷题名
                    RQ: model.SIGNATURE_TIME, //日期
                    YS: model.DOC_PAGE_COUNT, //页数
                    MJ: model.SECRET_LEVEL, //密级
                    GDR: @((Session["UserInfo"] as user).USER_NO), //归档人
                    WJ: model.ATTACHMENT //文件 base64格式
                }, //需要传入的数据，json格式
                success: function (msg) { //result是返回值 result=1 表示成功 result=0 表示失败，errMsg为错误信息
                    if (msg.result == "1") { //成功
                    } else { //失败，输出错误信息
                        alert(msg.errMsg);
                    }
                }
            });
        }
    </script>
}